package com.dongge.service;

import java.util.List;

/**
 * 分页的过程
 * 首先根据条件组合hsql语句
 * 获取数据记录
 */
public class Page {

    private List msgPage;//当前页的数据
    private int currentPage;//当前页
    private int numPage;//页数
    private int sizePage;//每页的信息条数
    private int countMsg;//总得信息条数

    private int indexBegin;
    private int indexEnd;

    /**
     * 输入的信息包括当前页面数据，当前页号，每页的信息条数，以及总页数
     * 每一次只显示十个页
     *
     */
    public Page(List msgPage, int currentPage, int sizePage, int countMsg) {
        this.msgPage = msgPage;
        this.currentPage = currentPage;
        this.sizePage = sizePage;
        this.countMsg = countMsg;
        this.numPage = (this.countMsg + this.sizePage -1)/this.sizePage;
        if(this.currentPage < 6){
            indexBegin = 1;
        }
        else{
            indexBegin = this.currentPage - 5;
        }
        indexEnd = indexBegin + 9;
        if(indexEnd > this.numPage){
            indexEnd = this.numPage;
        }
    }

    public List getMsgPage() {
        return msgPage;
    }

    public void setMsgPage(List msgPage) {
        this.msgPage = msgPage;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getNumPage() {
        return numPage;
    }

    public void setNumPage(int numPage) {
        this.numPage = numPage;
    }

    public int getSizePage() {
        return sizePage;
    }

    public void setSizePage(int sizePage) {
        this.sizePage = sizePage;
    }

    public int getCountMsg() {
        return countMsg;
    }

    public void setCountMsg(int countMsg) {
        this.countMsg = countMsg;
    }

    public int getIndexBegin() {
        return indexBegin;
    }

    public void setIndexBegin(int indexBegin) {
        this.indexBegin = indexBegin;
    }

    public int getIndexEnd() {
        return indexEnd;
    }

    public void setIndexEnd(int indexEnd) {
        this.indexEnd = indexEnd;
    }
}
